package com.nineclock.auth.exception;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;

/**
 * @author 黑马程序员
 * @Company http://www.ithiema.com
 * @Version 1.0
 */
public class NcOAuthExceptionJacksonSerializer extends StdSerializer<NcOAuth2Exception> {


    public NcOAuthExceptionJacksonSerializer() {
        super(NcOAuth2Exception.class);
    }

    @Override
    public void serialize(NcOAuth2Exception e, JsonGenerator generator, SerializerProvider provider) throws IOException {
        generator.writeStartObject();
        generator.writeObjectField("success", false);
        generator.writeObjectField("code", e.getHttpErrorCode());
        generator.writeObjectField("message", e.getMessage());
        generator.writeEndObject();
    }
}
